package com.mihu.stmall.manager.mapper;

import com.mihu.stmall.manager.entiy.Admin;
import org.apache.ibatis.annotations.*;

@Mapper
public interface AdminMapper {
    //添加
    @Insert("insert into admin (username,password,salt,phone,email,realname)" +
            "value(#{username},#{password},#{salt},#{phone},#{email},#{realname})")
    int insert(Admin admin);

    @Delete("delete from admin where id=#{id}")
    int delete(Integer id);


    //更新
    @Update({
            "<script>",
            "update admin",
            "<set>",
            "<if test='password !=null and password.length>0'> password=#{password},</if>",
            "<if test='salt !=null and salt.length>0'> salt=#{salt},</if>",
            "<if test='phone !=null and phone.length>0'> phone=#{phone},</if>",
            "<if test='email !=null and email.length>0'> email=#{email},</if>",
            "<if test='realname !=null and realname.length>0'> realname=#{realname},</if>",
            "<if test='status !=null'> status=#{status},</if>",
            "where id=#{id}",
            "</set>",
            "</script>",
    })
    int update(Admin admin);

    @Select("select * from admin where username=#{username}")
    //根据用户名
    Admin selectByUsername(String username);
    @Select("select * from admin where id=#{id}")
    //根据ID
    Admin selectById(Integer id);

}
